
#include "gtest/gtest.h"

extern bool sortByCol(int *matrix, int row, int col, int sort_by_col);

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}


TEST(sortByCol, test_success) {
    int matrix[4][3] = {{1, 10, 3}, {9, 8, 7}, {10, 12, 13}, {20, 1, 21}, };
    int row = 4;
    int col = 3;
    int sort_by_col = 2;
    bool result = sortByCol((int *)matrix, row, col, sort_by_col);
    ASSERT_NE(result, 0);

    int expect_result[4][3] = {{20, 1, 21}, {9, 8, 7},{1, 10, 3}, {10, 12, 13},  };
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            EXPECT_EQ(matrix[i][j], expect_result[i][j]);
        }
    }
}

TEST(sortByCol, test_failed) {
    int matrix[4][3] = {{1, 10, 3}, {9, 8, 7}, {10, 12, 13}, {20, 1, 21}, };
    int row = 4;
    int col = 3;
    int sort_by_col = 3;
    bool result = sortByCol((int *)matrix, row, col, sort_by_col);
    ASSERT_EQ(result, 0);
}